Jump to content

- Functions

- # LaunchHTTPRequest()

  Followers 0

  Lua → VBScript

  This function calls (launches) a given URL (http request) and returns true if the request returns without error.

  Please see the Introduction chapter for some usage instructions.

      ---------------------------------------------------------------------
      -- LaunchHTTPRequest
      --
      -- Launches given URL.
      --
      -- Parameter:
      --   sURL        complete url
      --
      -- return value:
      --   boolean     true  - request returned with code 200
      --               false - request returned with code <> 200
      ----------------------------------------------------------------------
      function LaunchHTTPRequest ( sURL )
          PBXScript.OutputTrace ("------> LaunchHTTPRequest ( sURL = '" .. sURL .. "' )")

          local bReturn = false

          local webreq = require "PBXWebRequest"
          if (webreq ~= nil) then

              local hsession, reponseCode

              hsession = webreq.new()
              hsession:URL(sURL)
              hsession:HttpVerb(PBXHttpVerbGet)

              local vBefore, vAfter, nDuration
              vBefore = os.time()

              responseCode = hsession:Execute()

              vAfter    = os.time()
              nDuration = os.difftime(vAfter, vBefore)

              PBXScript.OutputTrace("Web request returned after " .. math.floor(nDuration) .. " seconds the response code " .. responseCode)

              bReturn = (responseCode == 200)

          end

          PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
          PBXScript.OutputTrace ("<------ LaunchHTTPRequest")

          return bReturn
      end

  This function makes use of the Server Script API class PBXWebRequest for the web request and the function PBXScript.OutputTrace() to write trace information into the SwyxServer trace file.

  This function was converted from VBScript into Lua from the initially posted version in this forum topic.

  By Tom Wellige

  - June 5, 2022
  Share
  Share
  Followers 0
  Previous Page LaunchCmd()
  Next Page LogCallIntoTextFile()

## Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.